#ifndef __ILIB_UTIL_LOCK_H_20120422__
#define __ILIB_UTIL_LOCK_H_20120422__

class iLock
{
public:
	inline iLock()
	{
#if defined(__WIN__)
		InitializeCriticalSection(&m_cs);
#endif
	}
	inline ~iLock()
	{
#if defined(__WIN__)
		DeleteCriticalSection(&m_cs);
#endif
	}
	inline void acquire()
	{
#if defined(__WIN__)
		EnterCriticalSection(&m_cs);
#endif
	}
	inline void release()
	{
#if defined(__WIN__)
		LeaveCriticalSection(&m_cs);
#endif
	}

#if defined(__WIN__)
	CRITICAL_SECTION m_cs;
#elif defined(__LINUX__)
	pthread_mutex_t  m_cs;
#endif
};
class iNullLock
{
public:
	inline void acquire() {}
	inline void release() {}
};
class iAutoLock
{
public:
	iAutoLock(iLock& lc)
		:m_lock(lc)
	{
		m_lock.acquire();
	}
	~iAutoLock()
	{
		m_lock.release();
	}

private:
	iLock&	m_lock;
};
#endif  //__ILIB_UTIL_LOCK_H_20120422__